package com.demo.juc.futuretask;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;

/**
 * @Author: shubin_yao
 * @Date: 2022/09/19/23:35
 * @Description: FutureTask + 线程池使用  多任务执行
 *
 */
public class FutureTaskThreadPool {

    public static void main(String[] args) {

        ExecutorService threadPool = Executors.newFixedThreadPool(3);

        FutureTask<String> futureTask1 = new FutureTask<>(new MyThread());
        threadPool.submit(futureTask1);

        FutureTask<String> futureTask2 = new FutureTask<>(new MyThread());
        threadPool.submit(futureTask2);

        FutureTask<String> futureTask3 = new FutureTask<>(new MyThread());
        new Thread(futureTask3).start();

        threadPool.shutdown();


    }



    static class MyThread implements Callable<String> {
        @Override
        public String call() throws Exception {
            System.out.println("执行了call()方法。。。");
            return "hello FutureTask";
        }
    }

}
